﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Core.Common;
using FortuneHeavenCommon.DataMap;

namespace FortuneHeavenDAL
{
    public class AdminUserDAL : BaseDAL
    {
        public List<AdminUser> GetUserButAdmin(int page, int size)
        {
            if (page <= 0)
            {
                page = 1;
            }
            string sql = @"select * from (
select [ID],[LoginName],[RealName],[NickName],[Password],[Status],[Roles],[Time],RoomFilter,CityFilter,ProvinceFilter
,ROW_NUMBER() OVER(ORDER BY ID DESC) ROW 
from AdminUser where IsAdmin <>1 or IsAdmin is null) FF
 WHERE FF.ROW BETWEEN  @p0 AND @p1";
            List<AdminUser> list = dbOper.Query<AdminUser>(sql, size * (page - 1) + 1, size * page);
            return list;
        }


        public AdminUser CheckUserPwd(string user, string password)
        {
            string sql = @"select [ID],[LoginName],[RealName],[NickName],[Password],[Status],[IsAdmin]
from AdminUser where LoginName =@p0 and Password =@p1";
            List<AdminUser> list = dbOper.Query<AdminUser>(sql, user, password);
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            return null;
        }

        public int GetTotalSize()
        {
            string sql = @"select count(id) from AdminUser where IsAdmin <>1 or IsAdmin is null ";
            return dbOper.GetScalar<int>(sql);
        }

       

    }
}
